package com.lagou.niancheng.core.session.defaults;


import com.lagou.niancheng.core.config.Configuration;
import com.lagou.niancheng.core.result.ResultSetConverter;
import com.lagou.niancheng.core.session.Executor;
import com.lagou.niancheng.core.session.SqlSession;
import com.lagou.niancheng.core.session.SqlSessionFactory;
import com.lagou.niancheng.core.transaction.TransactionManager;

public class DefaultSqlSessionFactory implements SqlSessionFactory {

    private Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }


    @Override
    public SqlSession openSession() {
        ResultSetConverter resultSetConverter = configuration.getResultSetConverter();
        TransactionManager transactionManager = configuration.getTransactionManager();

        Executor executor = new DefaultExecutor(resultSetConverter, transactionManager);
        return new DefaultSqlSession(configuration, executor, transactionManager);
    }

    @Override
    public Configuration getConfiguration() {

        return configuration;
    }
}
